package zy3;

/**
 * 学生类
 */
public class Student {
    private String name;
    private int age;
    private String gender;

    public Student(){

    }

    public Student(String name,int age,String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    //学习
    public void study(String name,int age,String gender){
        String regex = "[\\u4e00-\\u9fa5]{2,4}"; //姓名必须是2~4个汉字。
        if(name.matches(regex)){
            this.name = name;
        }
        else{
            this.name = "无名氏";
            System.err.println("姓名必须是2~4个汉字。");
        }

        if (this.age <= 100 || this.age >= 1){
            this.age = age;
        }else {
            this.age = 18;
            System.out.println("年龄必须介于1~100之间!");
        }

        if ("男".equals(gender) || "女".equals(gender)){
            this.gender = gender;
        }else {
            this.gender = "男";
            System.out.println("性别只能是男或者女");
        }
        System.out.println(this.name+"在学习了");
    }

    //睡觉
    public void sleep(String name,int age,String gender){
        String regex = "[\\u4e00-\\u9fa5]{2,4}"; //姓名必须是2~4个汉字。
        if(name.matches(regex)){
            this.name = name;
        }
        else{
            this.name = "无名氏";
            System.err.println("姓名必须是2~4个汉字。");
        }

        if (this.age <= 100 || this.age >= 1){
            this.age = age;
        }else {
            this.age = 18;
            System.out.println("年龄必须介于1~100之间!");
        }

        if ("男".equals(gender) || "女".equals(gender)){
            this.gender = gender;
        }else {
            this.gender = "男";
            System.out.println("性别只能是男或者女");
        }
        System.out.println(this.name+"在睡觉了");
    }


    //说话
    public void speak(String name,int age,String gender){
        String regex = "[\\u4e00-\\u9fa5]{2,4}"; //姓名必须是2~4个汉字。
        if(name.matches(regex)){
            this.name = name;
        }
        else{
            this.name = "无名氏";
            System.err.println("姓名必须是2~4个汉字。");
        }

        if (this.age <= 100 || this.age >= 1){
            this.age = age;
        }else {
            this.age = 18;
            System.out.println("年龄必须介于1~100之间!");
        }

        if ("男".equals(gender) || "女".equals(gender)){
            this.gender = gender;
        }else {
            this.gender = "男";
            System.out.println("性别只能是男或者女");
        }
        System.out.println(this.name+"在说话了");
    }

    public static void main(String[] args) {
        Student student = new Student();
        student.study("张三",18,"男");
        student.sleep("李四",19,"男");
        student.speak("王五",20,"女");
    }
}
